package org.mobilesynergies.epic.client.parameter;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import org.jivesoftware.smackx.FormField;

public class StringParameter extends Parameter {

	private String mValue = "";

	public StringParameter(String value) {
		setValue(value);
	}
	
	public StringParameter(HashMap<String, String> map) {
		if(map.containsKey(KEY_VALUE)){
			mValue = map.get(KEY_VALUE);				
		}
	}


	/**
	 * @param mValue the mValue to set
	 */
	public void setValue(String value) {
		this.mValue = value;
	}

	/**
	 * @return the mValue
	 */
	public String getValue() {
		return mValue;
	}
	
	@Override
	public String getValueAsString() {
		return getValue();
	}
	
	@Override
	public String getType() {
		return Parameter.TYPENAME_STRING;
	}
	
	@Override
	public String toXml(String name) {
		String type = String.class.getCanonicalName();
		String value = mValue; 
		String extraattributes = null;
		String extraxml = null;
		return toXml(name, type, value, extraattributes, extraxml);
	}
	
	@Override
	public Set<FormField> toFormFields(String name) {
		Set<FormField> set = new HashSet<FormField>();
		FormField f1 = new FormField(name);
		f1.setLabel(name);
		f1.setType(FormField.TYPE_TEXT_SINGLE);
		f1.addValue(mValue);
		set.add(f1);
		return set;
	}

}
